import React from 'react';

// class Person {
//   name: string;
//   age: number;
//   constructor(name: string, age: number) {
//     this.name = name;
//     this.age = age;
//   }
//   getName(): string {
//     return '你的名字：' + this.name;
//   }
// }

// var p = new Person('小丽', 18);
// var p2 = new Person('小丽', 18);
// console.log(p.name);
// console.log(p.getName());

/* ***************************************** */

interface Clonable<T> {
  clone(): T;
}
class Person implements Clonable<Person> {
  name: string | undefined;
  age: number | undefined;
  Single: any;
  constructor(name?: string, age?: number) {
    this.name = name;
    this.age = age;
  }
  getName(): string {
    return '你的名字：' + this.name;
  }
  clone(): Person {
    if (!this.Single) {
      this.Single = new Person();
    }
    this.Single.name = this.name;
    this.Single.age = this.age;
    this.Single.getName = this.getName;
    return this.Single;
  }
}

let p = new Person('小丽', 18);

let cloneObj = p.clone();
console.log(cloneObj.getName());

let cloneObj1 = p.clone();
console.log(cloneObj1.getName());

/* ***************************************** */
interface Greeting {
  name: string;
}

const Hello = (props: Greeting) => <h1>Hello {props.name}</h1>;

export default Hello;
